package com.haidechizi.i18n.common.support;

import com.haidechizi.i18n.common.annotation.I18nModel;
import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;
import java.util.Map;

@Slf4j
public abstract class BaseI18nModelMappingBinding implements I18nModelMappingBinding {

    /**
     * 动态初始化I18nReflectUtils
     * 实现类和I18nModel的绑定关系
     */
    @Override
    public void binding() {
        Map<Class<?>, I18nModel> bindingData = getBindingData();
        log.info("自定义绑定关系,data:{}", bindingData);
        bindingData.forEach(I18nReflectUtils::setI18nModelAnnotation);
    }

    /**
     * 设置Class和I18nModel的绑定关系
     *
     * @return
     */
    public abstract Map<Class<?>, I18nModel> getBindingData();

    protected I18nModel getI18nModel(final String systemCode, final String businessCode, final String businessKey) {
        I18nModel i18nModel = new I18nModel() {

            @Override
            public String systemCode() {
                return systemCode;
            }

            @Override
            public String businessCode() {
                return businessCode;
            }

            @Override
            public String businessKey() {
                return businessKey;
            }

            @Override
            public Class<? extends Annotation> annotationType() {
                return I18nModel.class;
            }
        };
        return i18nModel;
    }
}
